﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MinStack
{
    public class MinStack
    {
        /// <summary>
        /// 存储栈
        /// </summary>
        private List<int> stack;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        public MinStack()
        {
            stack = new List<int>();
        }

        /// <summary>
        /// 进栈
        /// </summary>
        /// <param name="x">进栈数字</param>
        public void Push(int x)
        {
            stack.Add(x);
        }

        /// <summary>
        /// 出栈
        /// </summary>
        public void Pop()
        {
            stack.RemoveAt(stack.Count - 1);
        }

        /// <summary>
        /// 顶部元素
        /// </summary>
        /// <returns>元素值</returns>
        public int Top()
        {
            return stack[stack.Count - 1];
        }

        /// <summary>
        /// 获取栈中最小值
        /// </summary>
        /// <returns>最小值</returns>
        public int GetMin()
        {
            return stack.Min();
        }
    }

    /**
     * Your MinStack object will be instantiated and called as such:
     * MinStack obj = new MinStack();
     * obj.Push(x);
     * obj.Pop();
     * int param_3 = obj.Top();
     * int param_4 = obj.GetMin();
     */
}
